<?php
class Aboutcountry
{
    /**
     * @var object Zend DB Adapter
     */
    private $_db;
    
    public function __construct()
    {
			$this->_db = Zend_Registry::get('db');
    }
    
    public function listPageContentAboutCountry()
    {
    	$this->_db->query("SET NAMES 'utf8'");
    	$rec_arr = $this->_db->fetchAll("
    		SELECT * FROM about_country
    	");
    	
    	return $rec_arr;
    }
    
    public function addPage($form_values)
    {
    	$category = $form_values['category'];
    	$page_title = $form_values['page_title'];
    	$page_description_en = addslashes($form_values['page_description_en']);
    	$page_description_ru = addslashes($form_values['page_description_ru']);
    	$status = $form_values['status'];
    	
    	$this->_db->query("SET NAMES 'utf8'");
    	$add_page = $this->_db->exec("
    		INSERT INTO about_country(category, title, description_en, description_ru, status)
    		VALUES('" . $category . "', '" . $page_title . "', '" . $page_description_en . "', '" . $page_description_ru . "', " . $status . ")
    	");
    	
    	$max_page_id = $this->_db->fetchRow("SELECT last_insert_id() AS MAX_PAGE_ID FROM about_country");
		$last_page_id = $max_page_id['MAX_PAGE_ID'];
    	
    	if($add_page)
    	{
    		echo "Page details has been successfully added";
    	}
    }
    
    public function updatePage($form_values)
    {
    	$page_id = $form_values['page_id'];
    	$category = $form_values['category'];
    	$page_title = $form_values['page_title'];
    	$page_description_en = addslashes($form_values['page_description_en']);
    	$page_description_ru = addslashes($form_values['page_description_ru']);
    	$status = $form_values['status'];
    	
    	$this->_db->query("SET NAMES 'utf8'");
    	$update_page = $this->_db->exec("
    		UPDATE about_country SET category = '" . $category . "', title = '" . $page_title . "', description_en = '" . $page_description_en . "', description_ru = '" . $page_description_ru . "', status = " . $status . "
    		WHERE page_id = " . $page_id);
    	
    	if($update_page)
    	{
    		echo "Page details has been successfully updated.";
    	}
    }
    
    public function getPageDetailsById($page_id)
    {
    	$this->_db->query("SET NAMES 'utf8'");
    	$rec_arr = $this->_db->fetchRow("
    		SELECT * FROM about_country
    		WHERE page_id = " . $page_id
    	);
    	
    	return $rec_arr;
    }
    
    public function deletePageData($page_id)
    {
    	$del_pagedata = $this->_db->exec("
    		DELETE FROM about_country
    		WHERE page_id = " . $page_id
    	);
    	
    	if($del_pagedata) {
    		echo "Page details has been successfully deleted.";
    	}
    }
}
?>